<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>DLC Search Engine: src/main/java/DataAccess/postgresql/PostgreSQLPostListDAO.java Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">DLC Search Engine
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Packages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">src/main/java/DataAccess/postgresql/PostgreSQLPostListDAO.java</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_postgre_s_q_l_post_list_d_a_o_8java.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="keyword">package </span>dataaccess.postgresql;
<a name="l00002"></a>00002 
<a name="l00003"></a>00003 <span class="keyword">import</span> com.utn.searchengine.Document;
<a name="l00004"></a>00004 <span class="keyword">import</span> com.utn.searchengine.DocumentResults;
<a name="l00005"></a>00005 <span class="keyword">import</span> com.utn.searchengine.Word;
<a name="l00006"></a>00006 <span class="keyword">import</span> dataaccess.dao.PostListDAO;
<a name="l00007"></a>00007 <span class="keyword">import</span> dataaccess.dbmanager.PostgreDBManager;
<a name="l00008"></a>00008 <span class="keyword">import</span> java.sql.Connection;
<a name="l00009"></a>00009 <span class="keyword">import</span> java.sql.PreparedStatement;
<a name="l00010"></a>00010 <span class="keyword">import</span> java.sql.ResultSet;
<a name="l00011"></a>00011 <span class="keyword">import</span> java.sql.SQLException;
<a name="l00012"></a>00012 <span class="keyword">import</span> java.util.ArrayList;
<a name="l00013"></a>00013 <span class="keyword">import</span> java.util.Collection;
<a name="l00014"></a>00014 <span class="keyword">import</span> java.util.HashMap;
<a name="l00015"></a>00015 <span class="keyword">import</span> java.util.Iterator;
<a name="l00016"></a>00016 <span class="keyword">import</span> java.util.List;
<a name="l00017"></a>00017 <span class="keyword">import</span> java.util.Map;
<a name="l00018"></a>00018 
<a name="l00023"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html">00023</a> <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html">PostgreSQLPostListDAO</a> <span class="keyword">implements</span> <a class="code" href="interfacedataaccess_1_1dao_1_1_post_list_d_a_o.html">PostListDAO</a> {
<a name="l00024"></a>00024     <span class="comment">/* Recupera los documentos candidatos de la busqueda</span>
<a name="l00025"></a>00025 <span class="comment">     *  @param ArrayList&lt;Word&gt; words</span>
<a name="l00026"></a>00026 <span class="comment">     * Return arraylist de los documentos candidatos</span>
<a name="l00027"></a>00027 <span class="comment">     */</span>
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a1ef85476551ad259886a7683054a8efc">00029</a>     <span class="keyword">public</span> ArrayList&lt;Document&gt; <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a1ef85476551ad259886a7683054a8efc">obtenerDocumentoCandidatos</a>(Collection&lt;String&gt; c) {
<a name="l00030"></a>00030         ArrayList&lt;Document&gt; ret = <span class="keyword">new</span> ArrayList();
<a name="l00031"></a>00031         ArrayList&lt;Word&gt; words = <span class="keyword">new</span> ArrayList();
<a name="l00032"></a>00032         <span class="keywordflow">for</span> (String name : c) {
<a name="l00033"></a>00033             words.add(<span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a>(name));
<a name="l00034"></a>00034         }
<a name="l00035"></a>00035         Iterator i = words.iterator();
<a name="l00036"></a>00036         StringBuilder cad = <span class="keyword">new</span> StringBuilder();
<a name="l00037"></a>00037         <span class="keywordflow">while</span> (i.hasNext()) {
<a name="l00038"></a>00038             <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word = (<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a>) i.next();
<a name="l00039"></a>00039             cad.append(<span class="stringliteral">&quot;&#39;&quot;</span>);
<a name="l00040"></a>00040             cad.append(word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>());
<a name="l00041"></a>00041             cad.append(<span class="stringliteral">&quot;&#39;&quot;</span>);
<a name="l00042"></a>00042             <span class="keywordflow">if</span> (i.hasNext()) {
<a name="l00043"></a>00043                 cad.append(<span class="stringliteral">&quot;,&quot;</span>);
<a name="l00044"></a>00044             }
<a name="l00045"></a>00045         }
<a name="l00046"></a>00046         PreparedStatement st;
<a name="l00047"></a>00047         Connection con;
<a name="l00048"></a>00048         <span class="keywordflow">try</span> {
<a name="l00049"></a>00049             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00050"></a>00050             <span class="keyword">synchronized</span> (con) {
<a name="l00051"></a>00051                 String query = <span class="stringliteral">&quot;select distinct d.url_Name,d.Modulo from postlist p inner join page d on p.id_Url = d.id_Url inner join word w on p.id_Word = w.id_Word  where w.name_Word in (&quot;</span> + cad.toString() + <span class="stringliteral">&quot;);&quot;</span>;
<a name="l00052"></a>00052                 st = con.prepareStatement(query);
<a name="l00053"></a>00053                 ResultSet results = st.executeQuery();
<a name="l00054"></a>00054                 <span class="keywordflow">while</span> (results.next()) {
<a name="l00055"></a>00055                     ret.add(<span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a>(results.getString(1), <span class="stringliteral">&quot;&quot;</span>, results.getDouble(2)));
<a name="l00056"></a>00056                 }
<a name="l00057"></a>00057                 results.close();
<a name="l00058"></a>00058                 st.close();
<a name="l00059"></a>00059             }
<a name="l00060"></a>00060         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00061"></a>00061             ret = null;
<a name="l00062"></a>00062         }
<a name="l00063"></a>00063         System.out.println(<span class="stringliteral">&quot;---Cantidad de documentos encontrados: &quot;</span> + ret.size());
<a name="l00064"></a>00064         <span class="keywordflow">return</span> ret;
<a name="l00065"></a>00065     }
<a name="l00066"></a>00066     <span class="comment">/* Recupera el nr de una palabra</span>
<a name="l00067"></a>00067 <span class="comment">     * @param Word word</span>
<a name="l00068"></a>00068 <span class="comment">     * return el nr  y -1 en caso de que no pudo recuperarse</span>
<a name="l00069"></a>00069 <span class="comment">     */</span>
<a name="l00070"></a>00070 
<a name="l00071"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a9f53887bb6b093f5539ab29b747a0ea6">00071</a>     <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a9f53887bb6b093f5539ab29b747a0ea6">getNrWord</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word) {
<a name="l00072"></a>00072         <span class="keywordtype">int</span> nr = 0;
<a name="l00073"></a>00073         PreparedStatement st;
<a name="l00074"></a>00074         Connection con;
<a name="l00075"></a>00075         <span class="keywordflow">try</span> {
<a name="l00076"></a>00076             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00077"></a>00077             <span class="keyword">synchronized</span> (con) {
<a name="l00078"></a>00078                 String query = <span class="stringliteral">&quot;select nr from Word where name_Word = ?&quot;</span>;
<a name="l00079"></a>00079                 st = con.prepareStatement(query);
<a name="l00080"></a>00080                 st.setString(1, word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>());
<a name="l00081"></a>00081                 ResultSet results = st.executeQuery();
<a name="l00082"></a>00082                 <span class="keywordflow">while</span> (results.next()) {
<a name="l00083"></a>00083                     nr = results.getInt(<span class="stringliteral">&quot;nr&quot;</span>);
<a name="l00084"></a>00084                 }
<a name="l00085"></a>00085                 results.close();
<a name="l00086"></a>00086                 st.close();
<a name="l00087"></a>00087             }
<a name="l00088"></a>00088         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00089"></a>00089             nr = -1;
<a name="l00090"></a>00090         }
<a name="l00091"></a>00091         <span class="keywordflow">return</span> nr;
<a name="l00092"></a>00092 
<a name="l00093"></a>00093     }
<a name="l00094"></a>00094     <span class="comment">/* Recupera la cantidad de veces que aparece una palabra en un documento</span>
<a name="l00095"></a>00095 <span class="comment">     * @param Word word</span>
<a name="l00096"></a>00096 <span class="comment">     * @param Document document</span>
<a name="l00097"></a>00097 <span class="comment">     * return el tf y -1 en caso de que no pudo recuperarse</span>
<a name="l00098"></a>00098 <span class="comment">     */</span>
<a name="l00099"></a>00099 
<a name="l00100"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a9cbdbd5df3be84767ad2d3cfe75ec608">00100</a>     <span class="keyword">public</span> <span class="keywordtype">int</span> <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a9cbdbd5df3be84767ad2d3cfe75ec608">getTF</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word, <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document) {
<a name="l00101"></a>00101         <span class="keywordtype">int</span> tf = 0;
<a name="l00102"></a>00102         PreparedStatement st;
<a name="l00103"></a>00103         Connection con;
<a name="l00104"></a>00104         <span class="keywordflow">try</span> {
<a name="l00105"></a>00105             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00106"></a>00106             <span class="keyword">synchronized</span> (con) {
<a name="l00107"></a>00107                 String query = <span class="stringliteral">&quot;select p.frequency from PostList p inner join page d on p.id_Url = d.id_Url inner join word w on p.id_Word = w.id_Word  where w.name_Word = ? and d.url_Name = ?&quot;</span>;
<a name="l00108"></a>00108                 st = con.prepareStatement(query);
<a name="l00109"></a>00109                 st.setString(1, word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>());
<a name="l00110"></a>00110                 st.setString(2, document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a874682a9030d3f8d4db5fc37378c187a">getLocation</a>());
<a name="l00111"></a>00111                 ResultSet results = st.executeQuery();
<a name="l00112"></a>00112                 <span class="keywordflow">while</span> (results.next()) {
<a name="l00113"></a>00113                     tf = results.getInt(1);
<a name="l00114"></a>00114                 }
<a name="l00115"></a>00115                 results.close();
<a name="l00116"></a>00116                 st.close();
<a name="l00117"></a>00117             }
<a name="l00118"></a>00118         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00119"></a>00119             System.out.println(<span class="stringliteral">&quot;exception en getTF&quot;</span> + ex.getMessage());
<a name="l00120"></a>00120             tf = -1;
<a name="l00121"></a>00121         }
<a name="l00122"></a>00122         <span class="keywordflow">return</span> tf;
<a name="l00123"></a>00123 
<a name="l00124"></a>00124     }
<a name="l00125"></a>00125     <span class="comment">/* graba un documento por palabra en el postlist indicandole la frecuencia</span>
<a name="l00126"></a>00126 <span class="comment">     * @param Word word</span>
<a name="l00127"></a>00127 <span class="comment">     * @param Document document</span>
<a name="l00128"></a>00128 <span class="comment">     * @param int fr es la frecuencia de la palbra en un documento</span>
<a name="l00129"></a>00129 <span class="comment">     * return true si se pudo grabar en la base de datos</span>
<a name="l00130"></a>00130 <span class="comment">     */</span>
<a name="l00131"></a>00131 
<a name="l00132"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#ad8afd230c04a70252ecfd9b3e146245f">00132</a>     <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#ad8afd230c04a70252ecfd9b3e146245f">grabarPostList</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word, <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document, <span class="keywordtype">int</span> fr) {
<a name="l00133"></a>00133 
<a name="l00134"></a>00134         PreparedStatement st;
<a name="l00135"></a>00135         Connection con;
<a name="l00136"></a>00136         <span class="keywordflow">try</span> {
<a name="l00137"></a>00137             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00138"></a>00138             <span class="keyword">synchronized</span> (con) {
<a name="l00139"></a>00139                 String query = <span class="stringliteral">&quot;SELECT fn_Save_Postlist(?,?,?);&quot;</span>;
<a name="l00140"></a>00140                 st = con.prepareStatement(query);
<a name="l00141"></a>00141                 st.setString(1, word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>());
<a name="l00142"></a>00142                 st.setString(2, document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a874682a9030d3f8d4db5fc37378c187a">getLocation</a>());
<a name="l00143"></a>00143                 st.setInt(3, fr);
<a name="l00144"></a>00144                 st.executeQuery();
<a name="l00145"></a>00145                 st.close();
<a name="l00146"></a>00146                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00147"></a>00147             }
<a name="l00148"></a>00148         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00149"></a>00149             System.out.println(<span class="stringliteral">&quot;&quot;</span> + ex.toString());
<a name="l00150"></a>00150             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00151"></a>00151 
<a name="l00152"></a>00152         }
<a name="l00153"></a>00153 
<a name="l00154"></a>00154     }
<a name="l00155"></a>00155 
<a name="l00156"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#ad60674df8151d0ad68a7116bba5297b9">00156</a>     <span class="keyword">public</span> <span class="keywordtype">boolean</span> <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#ad60674df8151d0ad68a7116bba5297b9">Contains</a>(String palabra) {
<a name="l00157"></a>00157         <span class="keywordtype">boolean</span> ret = <span class="keyword">false</span>;
<a name="l00158"></a>00158         PreparedStatement st;
<a name="l00159"></a>00159         Connection con;
<a name="l00160"></a>00160         <span class="keywordflow">try</span> {
<a name="l00161"></a>00161             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00162"></a>00162             <span class="keyword">synchronized</span> (con) {
<a name="l00163"></a>00163                 String query = <span class="stringliteral">&quot;select  * from postlist p  inner join word w on p.id_Word = w.id_Word where w.name_Word = ?&quot;</span>;
<a name="l00164"></a>00164                 st = con.prepareStatement(query);
<a name="l00165"></a>00165                 st.setString(1, palabra);
<a name="l00166"></a>00166                 ResultSet results = st.executeQuery();
<a name="l00167"></a>00167                 <span class="keywordflow">if</span> (results.next()) {
<a name="l00168"></a>00168                     ret = <span class="keyword">true</span>;
<a name="l00169"></a>00169                 }
<a name="l00170"></a>00170                 results.close();
<a name="l00171"></a>00171                 st.close();
<a name="l00172"></a>00172             }
<a name="l00173"></a>00173         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00174"></a>00174         }
<a name="l00175"></a>00175         <span class="keywordflow">return</span> ret;
<a name="l00176"></a>00176     }
<a name="l00177"></a>00177 
<a name="l00178"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a08dd503b058dc03570751af250b20fe2">00178</a>     <span class="keyword">public</span> ArrayList&lt;Word&gt; <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a08dd503b058dc03570751af250b20fe2">getWordsDocument</a>(<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document) {
<a name="l00179"></a>00179         ArrayList&lt;Word&gt; ret = <span class="keyword">new</span> ArrayList();
<a name="l00180"></a>00180         PreparedStatement st;
<a name="l00181"></a>00181         Connection con;
<a name="l00182"></a>00182         <span class="keywordflow">try</span> {
<a name="l00183"></a>00183             con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00184"></a>00184             <span class="keyword">synchronized</span> (con) {
<a name="l00185"></a>00185                 String query = <span class="stringliteral">&quot;select w.name_Word, w.nr,p.frequency  from postlist p inner join page d on p.id_Url = d.id_Url inner join word w on p.id_Word = w.id_Word  where d.url_Name = ?&quot;</span>;
<a name="l00186"></a>00186                 st = con.prepareStatement(query);
<a name="l00187"></a>00187                 st.setString(1, document.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html#a874682a9030d3f8d4db5fc37378c187a">getLocation</a>());
<a name="l00188"></a>00188                 ResultSet results = st.executeQuery();
<a name="l00189"></a>00189                 <span class="keywordflow">while</span> (results.next()) {
<a name="l00190"></a>00190                     ret.add(<span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a>(results.getString(1), results.getInt(2), results.getInt(3)));
<a name="l00191"></a>00191                 }
<a name="l00192"></a>00192                 results.close();
<a name="l00193"></a>00193                 st.close();
<a name="l00194"></a>00194             }
<a name="l00195"></a>00195         } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00196"></a>00196             ret = null;
<a name="l00197"></a>00197         }
<a name="l00198"></a>00198         <span class="keywordflow">return</span> ret;
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     }
<a name="l00201"></a>00201 
<a name="l00202"></a><a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a3dbc10958c2c69645f508637510ad10e">00202</a>     <span class="keyword">public</span> List&lt;DocumentResults&gt; <a class="code" href="classdataaccess_1_1postgresql_1_1_postgre_s_q_l_post_list_d_a_o.html#a3dbc10958c2c69645f508637510ad10e">getFilteredCandidates</a>(Collection&lt;String&gt; c) {
<a name="l00203"></a>00203         {
<a name="l00204"></a>00204             ArrayList&lt;DocumentResults&gt; ret = <span class="keyword">new</span> ArrayList();
<a name="l00205"></a>00205             ArrayList&lt;Word&gt; words = <span class="keyword">new</span> ArrayList();
<a name="l00206"></a>00206             <span class="keywordflow">for</span> (String name : c) {
<a name="l00207"></a>00207                 words.add(<span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a>(name));
<a name="l00208"></a>00208             }
<a name="l00209"></a>00209             Iterator i = words.iterator();
<a name="l00210"></a>00210             StringBuilder cad = <span class="keyword">new</span> StringBuilder();
<a name="l00211"></a>00211             <span class="keywordflow">while</span> (i.hasNext()) {
<a name="l00212"></a>00212                 <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a> word = (<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html">Word</a>) i.next();
<a name="l00213"></a>00213                 cad.append(<span class="stringliteral">&quot;&#39;&quot;</span>);
<a name="l00214"></a>00214                 cad.append(word.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_word.html#a0178ae154e1b998a526042de4fe525be">getName</a>());
<a name="l00215"></a>00215                 cad.append(<span class="stringliteral">&quot;&#39;&quot;</span>);
<a name="l00216"></a>00216                 <span class="keywordflow">if</span> (i.hasNext()) {
<a name="l00217"></a>00217                     cad.append(<span class="stringliteral">&quot;,&quot;</span>);
<a name="l00218"></a>00218                 }
<a name="l00219"></a>00219             }
<a name="l00220"></a>00220             PreparedStatement st;
<a name="l00221"></a>00221             Connection con;
<a name="l00222"></a>00222             <span class="keywordflow">try</span> {
<a name="l00223"></a>00223                 con = <a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html">PostgreDBManager</a>.<a class="code" href="classdataaccess_1_1dbmanager_1_1_postgre_d_b_manager.html#a1f08589b938029b7e2c0fac3080f651e">getConnection</a>();
<a name="l00224"></a>00224                 <span class="keyword">synchronized</span> (con) {
<a name="l00225"></a>00225                     Map&lt;String, Integer&gt; documentsCount = <span class="keyword">new</span> HashMap&lt;String, Integer&gt;();
<a name="l00226"></a>00226                     Map&lt;String, Integer&gt; wordsCount = <span class="keyword">new</span> HashMap&lt;String, Integer&gt;();
<a name="l00227"></a>00227                     StringBuilder query = <span class="keyword">new</span> StringBuilder(<span class="stringliteral">&quot;select   w.name_Word,p.frequency, d.url_Name,d.Modulo &quot;</span>);
<a name="l00228"></a>00228                     query.append(<span class="stringliteral">&quot;from postlist p inner join page d on p.id_Url = d.id_Url inner join word w on p.id_Word = w.id_Word &quot;</span>);
<a name="l00229"></a>00229                     query.append(<span class="stringliteral">&quot;where w.name_Word in (&quot;</span>).append(cad.toString()).append(<span class="stringliteral">&quot;) &quot;</span>);
<a name="l00230"></a>00230                     query.append(<span class="stringliteral">&quot;group by  w.name_Word,p.frequency, d.url_Name,d.Modulo &quot;</span>);
<a name="l00231"></a>00231                     query.append(<span class="stringliteral">&quot;order by  w.name_Word,p.frequency desc;&quot;</span>);
<a name="l00232"></a>00232                     st = con.prepareStatement(query.toString());
<a name="l00233"></a>00233                     ResultSet results = st.executeQuery();
<a name="l00234"></a>00234                     String wordToCompare = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00235"></a>00235                     String wordToIgnore = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00236"></a>00236                     <span class="keywordtype">int</span> count = 0;
<a name="l00237"></a>00237                     <span class="keywordflow">while</span> (results.next()) {
<a name="l00238"></a>00238                         <span class="keywordflow">if</span> (!wordToIgnore.equalsIgnoreCase(results.getString(1)) &amp;&amp; count &lt; 5) {
<a name="l00239"></a>00239                             <span class="keywordflow">if</span> (!wordToCompare.equalsIgnoreCase(results.getString(1))) {
<a name="l00240"></a>00240                                 wordToCompare = results.getString(1);
<a name="l00241"></a>00241                                 count = 1;
<a name="l00242"></a>00242                             } <span class="keywordflow">else</span> {
<a name="l00243"></a>00243                                 count++;
<a name="l00244"></a>00244                             }
<a name="l00245"></a>00245                             <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a> document = <span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document.html">Document</a>(results.getString(3), <span class="stringliteral">&quot;&quot;</span>, results.getDouble(4));
<a name="l00246"></a>00246                             <span class="keywordflow">if</span> (!documentsCount.containsKey(results.getString(3).toString())) {
<a name="l00247"></a>00247                                 documentsCount.put(results.getString(3), 1);
<a name="l00248"></a>00248 
<a name="l00249"></a>00249                                 ret.add(<span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_results.html">DocumentResults</a>(document, 1));
<a name="l00250"></a>00250                             } <span class="keywordflow">else</span> {
<a name="l00251"></a>00251                                 <span class="keywordtype">int</span> newValue = documentsCount.get(results.getString(3));
<a name="l00252"></a>00252                                 newValue++;
<a name="l00253"></a>00253                                 <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_results.html">DocumentResults</a> documentResult = ret.get(ret.indexOf(<span class="keyword">new</span> <a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_results.html">DocumentResults</a>(document, newValue)));
<a name="l00254"></a>00254                                 documentResult.<a class="code" href="classcom_1_1utn_1_1searchengine_1_1_document_results.html#a6f1eae104e90cac795ab4b6a539b1668">setNumberOfQueryWords</a>(newValue);
<a name="l00255"></a>00255                             }
<a name="l00256"></a>00256                         } <span class="keywordflow">else</span> {
<a name="l00257"></a>00257                             count = 0;
<a name="l00258"></a>00258                             wordToIgnore = results.getString(1);
<a name="l00259"></a>00259                         }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261                     }
<a name="l00262"></a>00262                     results.close();
<a name="l00263"></a>00263                     st.close();
<a name="l00264"></a>00264                 }
<a name="l00265"></a>00265             } <span class="keywordflow">catch</span> (SQLException ex) {
<a name="l00266"></a>00266                 System.out.println(<span class="stringliteral">&quot;Exception retrieving filtered candidate documents&quot;</span> + ex.getMessage());
<a name="l00267"></a>00267                 ret = null;
<a name="l00268"></a>00268             }
<a name="l00269"></a>00269             <span class="keywordflow">return</span> ret;
<a name="l00270"></a>00270         }
<a name="l00271"></a>00271     }
<a name="l00272"></a>00272 }
</pre></div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Thu Feb 16 2012 02:45:40 for DLC Search Engine by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
